<?php
if (!defined('isIncluded') || $_SESSION['GroepID'] == 1 || $_SESSION['GroepID'] == 4)
	header('location: index.php');

if(empty($_GET['id']))
	header("location: index.php?c=error&p=notfound");
?>
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		oTable = $('#table').dataTable({
			"bJQueryUI": true,
			"sPaginationType": "full_numbers"
		});
	});
</script>

<form name="productList" method="post" action="index.php?c=product&p=winkelwagen">
	<div id="demo">
		<table cellpadding="0" cellspacing="0" border="0" class="display" id="table">
			<thead>
				<tr>
					<th>Artikelnummer</th>
					<th>Artikelnaam</th>
					<th>Kleur</th>
					<th>Maat</th>
					<th>Afbeelding</th>
					<th>Verkoopprijs</th>
					<th>Aantal</th>
					<th>Subtotaal</th>
				</tr>
			</thead>

			<tbody>
				<?php

				$gebruiker = Gebruiker::get(Bestelling::get($_GET['id'])->getProperty("GebruikerID"));
				$BetaalMethode = $gebruiker->getProperty("BetaalMethode");
				$Koers = $gebruiker->getProperty("PuntenKoers");
				$startBedrag = $gebruiker->getProperty("Budget");
				global $db;

				$sth = $db->prepare("SELECT product.* FROM bestelling_product JOIN product ON (bestelling_product.ProductID=product.ProductID) WHERE bestelling_product.BestellingID = :bestellingid");
				$sth->bindParam(":bestellingid", $_GET['id']);
				$sth->execute();
				$result = $sth->fetchAll(PDO::FETCH_ASSOC);

				$Totaal = 0;

				if (!empty($result))
					foreach ($result as $key => $value)
					{
						$sth = $db->prepare("SELECT Aantal, Totaalprijs FROM bestelling_product WHERE BestellingID = :bestellingid AND ProductID = :productid");
						$sth->bindParam(":bestellingid", $_GET['id']);
						$sth->bindParam(":productid", $value["ProductID"]);
						$sth->execute();
						$result2 = $sth->fetch(PDO::FETCH_ASSOC);

						$verkoopprijs = ($BetaalMethode == "punten")? $value["Verkoopprijs"] . ' pnt.' : '&euro; ' . $value["Verkoopprijs"];
						$sub = ($BetaalMethode == "punten")? $result2["Totaalprijs"] . ' pnt.' : '&euro; ' . $result2["Totaalprijs"];
						?>

						<tr style="text-align: center">
							<td><?php echo $value["Artikelnummer"]; ?></td>
							<td><?php echo $value["Artikelnaam"]; ?></td>
							<td><?php echo $value["Kleur"]; ?></td>
							<td><?php echo $value["Maat"]; ?></td>
							<td><a target="_blank" href="<?php echo $value["Afbeelding"]; ?>">Afbeelding</a></td>
							<td><?php echo $verkoopprijs; ?></td>
							<td><?php echo $result2["Aantal"]; ?></td>
							<td><?php echo $sub; ?></td>
						</tr>
						<?php
						$Totaal = $Totaal + $result2['Totaalprijs'];
					}
					$Totaal = (($BetaalMethode == "punten")? $Totaal . ' pnt.' : '&euro; ' . $Totaal);
				?>
			</tbody>
		</table>
	</div>
	<br />
	<span style="font-size: 10pt; float: right">Totale waarde bestelling: <?php echo $Totaal;?></span>
	<br /><br /><a href="index.php?c=bestelling&p=list" class="button" >Terug</a>
</form>
<br />